package top.vanchor.myblog2back.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import top.vanchor.myblog2back.entity.BlogGame;
import top.vanchor.myblog2back.mapper.BlogGameMapper;
import top.vanchor.myblog2back.service.IBlogGameService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Ding
 * @since 2022-01-24
 */
@Service
public class BlogGameServiceImpl extends ServiceImpl<BlogGameMapper, BlogGame> implements IBlogGameService {
    @Resource
    private BlogGameMapper blogGameMapper;

    @Override
    public PageInfo<BlogGame> getGameList(Integer index, Integer num, Integer memberType, String searchText) {
        PageHelper.startPage(index,num);
        QueryWrapper<BlogGame> wrapper = new QueryWrapper<>();
        if ( memberType!=0){
            wrapper.eq("member_type",memberType);
        }
        if (searchText!=null && !searchText.equals("")){
            wrapper.like("game_name",searchText)
                    .or()
            .like("info",searchText);
        }
        wrapper.gt("status",0);
        return new PageInfo<>(blogGameMapper.selectList(wrapper));
    }

    @Override
    public BlogGame getGameById(Integer gameId) {
        QueryWrapper<BlogGame> wrapper = new QueryWrapper<>();
        wrapper.eq("game_id",gameId);
        return blogGameMapper.selectOne(wrapper);
    }
}
